<!--
 * @Description  : 公告
 * @Author       : zhao
 * @Date         : 2022-07-11 14:05:38
 * @LastEditors  : zhao
 * @LastEditTime : 2022-08-05 09:07:42
-->

<template>
	<div class="Borrow">
		<ztable :searchType="searchType" :tableHeader="tableHeader" :tableData="tableData" :title="'公告管理'" />
	</div>
</template>

<script setup lang='ts'>
import { ref, onMounted, watch } from 'vue';
import ztable from '/@/components/zTable/index.vue';

import BFData from '/@/views/zPublicity/publicity.ts';
import { useTableInfo } from '/@/stores/ztable'
import { usePublicity } from '/@/stores/publicity'
import { useRouter } from 'vue-router'
import { toRaw } from '@vue/reactivity'
const router = useRouter()

const searchType = ref(BFData.searchType);
const tableHeader = ref(BFData.tableHeader);
const tableData = ref(BFData.tableData);

const { zTable, getTableData } = useTableInfo()
let useTableInfos = useTableInfo()
useTableInfos.$reset()
const initData = async () => {
	// useTableInfos.zTable.routerUrl = "/updataAndMaintain/details"
	useTableInfos.zTableFunction.add = true
	useTableInfos.zTableFunction.modify = true
	useTableInfos.zTableFunction.delete = true
	useTableInfos.zTable.routerUrl = "/Publicity/details"
	useTableInfos.zTable.mdName.name = "usePublicity"
	useTableInfos.zTable.mdName.url = "getNoticeList"
	await getTableData()
}
initData()


//打开新增页
const add = () => {
	// addUserRef.value.openDialog();
	router.push("/Publicity/add")
}
//打开详情页
const edit = () => {
	// editUserRef.value.openDialog();
	router.push("/Publicity/edit")
}
const del = async () => {
	// editUserRef.value.openDialog();

	const pub = usePublicity()
	const row = toRaw(useTableInfos.zTable.selectRows)
	let arr = row.map((e: any) => { return e.id })
	const res = await pub.deleteNotice({ id: arr })
	getTableData()
	useTableInfos.zTableFunDelShow = false
}
useTableInfos.$subscribe((mutation: any, state) => {
	const sta = toRaw(state)
	if (sta.zTableFunAddShow) add()
	if (sta.zTableFunEditShow) edit()
	if (sta.zTableFunDelShow) del()

})

</script>
<style lang='scss' scoped>
</style>
